package com.kuiandjie.web;


import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.kuiandjie.entity.Goal;
import com.kuiandjie.entity.Project;
import com.kuiandjie.service.GoalService;

public class ProjectdetailServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
			HttpSession session = request.getSession();
			Project curp = (Project) session.getAttribute("curp");
			
			if(curp != null) {
				String role = (String) session.getAttribute("role");
				
				GoalService gs = new GoalService();
				List<Goal> goallist = null;
				
				if("leader".equals(role) || "member".equals(role)) {
					goallist = gs.findAllGoalByPid(curp.getId());
				}else {
					response.sendRedirect("main.jspx");
					return;
				}
				
				request.setAttribute("goallist", goallist);
				request.getRequestDispatcher("WEB-INF/views/projectdetail.jsp").forward(request, response);
			} else {
				response.sendRedirect("main.jspx");
			}
		
	}
}
